<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>网站后台管理模版</title>
		<link rel="stylesheet" href="lib/layui-v2.5.5/css/layui.css" media="all">
		<link rel="stylesheet" href="css/public.css" media="all">

	</head>
	<body>

	<form class="layui-form layui-from-pane" action="" style="margin-top:20px" lay-filter="formSysuser">

		<input type="hidden" name="id" value="">

		<div class="layui-form-item">
			<label class="layui-form-label">姓名</label>
			<div class="layui-input-block">
				<input type="text" name="name"  required  lay-verify="required" autocomplete="off" placeholder="请输入账号名称" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">性别</label>
			<div class="layui-input-block">
				<input type="radio" name="sex" value="M" title="男">
				<input type="radio" name="sex" value="F" title="女">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">电话</label>
			<div class="layui-input-block">
				<input type="text" name="telephone"  autocomplete="off" placeholder="请输入电话号码" class="layui-input" lay-verify="telephone|number">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">邮箱</label>
			<div class="layui-input-block">
				<input type="text" name="email" required  lay-verify="required |email" autocomplete="off" placeholder="请输入邮箱" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">工号</label>
			<div class="layui-input-block">
				<input type="text" name="number" required  lay-verify="required" autocomplete="off" placeholder="请输入工号" class="layui-input" >
			</div>
		</div>


		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">简介</label>
			<div class="layui-input-block">
				<textarea placeholder="请输入个人简介" class="layui-textarea" name="introduce"></textarea>
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">给定角色</label>
			<div class="layui-input-block" id="demo1">
			</div>
		</div>


		<div class="layui-form-item" style="margin-top:40px">
			<div class="layui-input-block">
				<button class="layui-btn  layui-btn-submit " lay-submit="" lay-filter="demo11">确认修改</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>

<script src="lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="api/baseApi.js" charset="utf-8"></script>
<script>
		layui.use(['laydate','table','layer','form','xmSelect'], function(){
					var form = layui.form
					,layer = layui.layer
					,$ = layui.$
					,xmSelect = layui.xmSelect;
			form.render();

			//获取页面传过来的数据
			let localData = layui.sessionData("sysuserData");
			console.log(localData);
			//给表单赋值
			form.val('formSysuser',localData.sysuser);

			//监听提交
			form.on('submit(demo11)', function(data) {
				//layer.msg(JSON.stringify(data.field));
				let arr = demo1.getValue();
				let arrId = arr.map(item => item.value)
				let roleIds = arrId.join()
				let req = data.field
				req['roleIds']=roleIds
				console.log("req")
				$.ajax({
					url: baseUrl + sysuserBaseUrl+edit+"sysuser",
					type:'put',
					dataType: "json",
					contentType: "application/json;charset=UTF-8",
					data: JSON.stringify(req),
					success:function (res) {
						if(res.code = "200"){
							parent.layer.msg('管理用户修改成功',{time:1000},function () {
								parent.location.reload();
							})
						}else{
							layer.msg(res.msg);
						}
					}
				})
				return false;
			});

			//查出所有的角色
			var demo1;
			$.ajax({
				type:'get',
				url: baseUrl + roleBaseUrl + view +'initRoleList',
				success:function(res){
					demo1=xmSelect.render({
						el:'#demo1',
						name:'role',
						data:res.data
					})
				}
			})

			//将已有的赋值
			$.ajax({
				url: baseUrl + roleBaseUrl + view +'getRoleSelectByUserId/'+ localData.sysuser.id,
				type:'get',
				success:function (res) {
					console.log(res.data)
					demo1.setValue(res.data || [])
				}
			})

		});
</script>
</body>
</html>